#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/SQS'
require 'basic_configuration'
require 'aws_context'
require 'pp'

# Delete the given queue

if ARGV[0] == '-?' || ARGV.size != 1
  puts "usage: delete-queue name"
  exit 1
end
name = ARGV[0]

Signal.trap("INT") do
  exit 2
end

config = BasicConfiguration.new
sqs = AwsContext.instance.sqs(*config.keys)
begin
  url = sqs.list_queues(name).first
  if url.nil? 
    puts "queue not found: #{name}"
    exit 1
  end
  res = sqs.delete_queue(url)
  puts "deleted #{name}"
rescue
  puts "error #{$!} #{name}"
  exit 1
end

